#include <iostream>
#include <string>
#include <memory>

class Fruit
{
public:
    Fruit() {}
    virtual void show() = 0;
};

class Apple : public Fruit
{
public:
    Apple() {}

    virtual void show()
    {
        std::cout << "这是一个苹果" << std::endl;
    }

private:
    std::string _color;
};

class Bannana:public Fruit
{
    public:
    Bannana(){}
    virtual void show()
    {
        std::cout<<"这是一个香蕉"<<std::endl;
    }
};

class FruitFactory 
{
    public:
    virtual std::shared_ptr<Fruit> create()=0;
};

class AppleFactory: public FruitFactory
{
    public:
    virtual std::shared_ptr<Fruit> create()
    {
        return std::make_shared<Apple>();
    }
};

class BannanaFactory: public FruitFactory
{
    public:
    virtual std::shared_ptr<Fruit> create()
    {
        return std::make_shared<Bannana>();
    }
};

int main()
{
    std::shared_ptr<FruitFactory> factory(new AppleFactory());
    std::shared_ptr<Fruit> fruit=factory->create();
    fruit->show();

    factory.reset(new BannanaFactory());
    fruit=factory->create();
    fruit->show();
    return 0;
}